<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #menu{
            width: 150px;
            list-style: none;
            margin: 0;
            padding: 0;
            border:1px solid #999;
            position: absolute;
            display: none;
        }
        #menu li{
            line-height: 30px;
            border-bottom: 1px dashed #999;
            text-align: center;
            cursor: pointer;
        }
        #menu li:last-child{
            border:0;
        }
        #menu li:hover{
            background-color: aquamarine;
        }
    </style>
</head>
<body style="height: 3000px;">
    <ul id="menu">
        <li>新建</li>
        <li>复制</li>
        <li>粘贴</li>
        <li>剪切</li>
        <li>属性</li>
    </ul>

    <script>
        let oMenu = document.getElementById('menu');
        document.oncontextmenu = function(ev){
            let x = ev.pageX;
            let y = ev.pageY;
            oMenu.style.display = 'block';
            oMenu.style.left = x +'px';
            oMenu.style.top = y +'px';
            return false;
        }
        document.onclick = function(){
            oMenu.style.display = 'none';
        }
    </script>
</body>
</html>